package com.yanqu.road.server.cmd.tradewar;

import com.yanqu.road.entity.tradewar.CrossTradeWarSimpleNotice;
import com.yanqu.road.logic.pb.CrossTradeWarPb;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.pb.cross.tradewar.CrossTradeWarProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.tradewar.CrossTradeWarMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

import java.util.List;

@Cmd(code = Protocol.C_CROSS_TRADE_WAR_SIMPLE_NOTICE, desc = "游戏服来取简略公告")
public class CrossTradeWarGetSimpleNoticeCmd extends CrossUnionCommand {
    private int activityId;
    private long battleUserId;
    private long battleServerId;
    private long enemyUserId;
    private long enemyServerId;
    private long reqUserId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        CrossTradeWarProto.CrossTradeWarSimpleNoticeReqMsg reqMsg = CrossTradeWarProto.CrossTradeWarSimpleNoticeReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        battleUserId = reqMsg.getUserId();
        battleServerId = reqMsg.getServerId();
        enemyUserId = reqMsg.getEnemyUserId();
        enemyServerId = reqMsg.getEnemyServerId();
        reqUserId = packet.getPlayerId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        List<CrossTradeWarSimpleNotice> dataList = CrossTradeWarMgr.getCrossTradeWarSimpleNoticeList(activityId, battleUserId, battleServerId, enemyUserId, enemyServerId);
        CrossTradeWarProto.CrossTradeWarSimpleNoticeRespMsg.Builder respMsg = CrossTradeWarProto.CrossTradeWarSimpleNoticeRespMsg.newBuilder();
        respMsg.setRet(0);
        CrossTradeWarProto.CrossTradeWarSimpleNoticeListMsg.Builder listMsg = CrossTradeWarPb.parseCrossTradeWarSimpleNoticeListMsg(dataList);
        respMsg.setDataList(listMsg);
        YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.U_CROSS_TRADE_WAR_SIMPLE_NOTICE, respMsg);
        MessageHelper.sendPacket(serverId, reqUserId, pbMsg);
    }

    @Override
    public void sendData() {

    }
}
